package com.fa4j.system.account.model;

import com.fa4j.common.base.model.BaseEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.regex.Pattern;

@Schema(description = "密码类型")
@Getter
@AllArgsConstructor
public enum AccountPasswordType implements BaseEnum {

    LOGIN(1, "登录密码", "[a-zA-Z0-9!@#$%^&*()_+-=]{8,32}", "必须是数字，大小字母和特殊字符(!@#$%^&*()_+-=]),长度8～32"),

    ;

    private final Integer code;
    private final String name;
    /**
     * 密码强度表达式
     */
    private final String strengthRegx;

    /**
     * 密码说明表达式
     */
    private final String strengthDesc;

    public void checkStrength(String password) {
        if (!Pattern.matches(strengthRegx, password)) {
            throw PasswordError.PASSWORD_STRENGTH_WEAK.build(strengthDesc);
        }
    }

}
